package com.yungu.swift.api.route.v1.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.api.facade.PassengerFacade;
import com.yungu.swift.api.utils.FileUploadUtil;
import com.yungu.swift.assets.driver.model.dto.CarModelDto;
import com.yungu.swift.assets.driver.model.param.CarModelSiteParam;
import com.yungu.swift.assets.driver.service.CarModelService;
import com.yungu.swift.assets.passenger.service.PassengerService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.constants.MagicConstant;
import com.yungu.swift.constants.OrderConstant;
import com.yungu.swift.order.model.param.ApiJoinListParam;
import com.yungu.swift.order.model.param.JoinOrderParam;
import com.yungu.swift.order.model.param.OrderEvaluateParam;
import com.yungu.swift.order.model.vo.ApiJoinValuationVo;
import com.yungu.swift.order.model.vo.JsonOrderDetailVo;
import com.yungu.swift.order.service.OrderFareService;
import com.yungu.swift.order.service.OrderJoinService;
import com.yungu.swift.order.service.OrderService;
import com.yungu.swift.system.sys.model.dto.SysPointSiteDto;
import com.yungu.swift.system.sys.model.dto.SysWayDto;
import com.yungu.swift.system.sys.model.param.SysWayRelateParam;
import com.yungu.swift.system.sys.model.vo.SysWayInfoVo;
import com.yungu.swift.system.sys.service.SysPointSiteService;
import com.yungu.swift.system.sys.service.SysWayService;
import com.yungu.swift.utils.MapUtils;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 乘客端拼车订单接口
 */
@Slf4j
@Controller
@RequestMapping(value = "/api/v1/passenger", method = {RequestMethod.POST, RequestMethod.GET})
@Api(value = "【乘客】【订单】【跨城】跨车拼车订单接口【亿的】", tags = "乘客跨城拼车订单相关操作")
public class JoinOrderApi extends BaseApi {

    @Reference
    private SysWayService sysWayService;
    @Reference
    private SysPointSiteService sysPointSiteService;
    @Reference
    private CarModelService carModelService;
    @Reference
    private OrderService orderService;
    @Reference
    private OrderFareService orderFareService;
    @Reference
    private OrderJoinService orderJoinService;
    @Reference
    private PassengerService passengerService;

    @Autowired
    private PassengerFacade passengerFacade;

    @RequestMapping(value = {"/join/pointMatchedByAreaSiteCheck"})
    @ResponseBody
    @ApiOperation(value = "校验某一坐标是否被某一区域类型起终点范围覆盖—— 已生效", response = ResponseData.class,
            notes = "DATA：是否匹配"
                    + "<br>isMatchOk-是否默认（即是否与当前定位匹配：0否 1是）")
    public ResponseData<Map<String, Integer>> pointMatchedByAreaSiteCheck(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "pasLng", value = "乘客经度", required = true) @RequestParam Double pasLng,
            @ApiParam(name = "pasLat", value = "乘客纬度", required = true) @RequestParam Double pasLat,
            @ApiParam(name = "targetSiteUuid", value = "目标（区域类型）起/终点UUID", required = true) @RequestParam String targetSiteUuid,
            @ApiParam(name = "originSiteUuid", value = "起点线路ID", required = false) @RequestParam(required = false) String originSiteUuid) {
        return sysWayService.pointMatchedByAreaSiteCheck(pasLng, pasLat, targetSiteUuid, originSiteUuid);
    }

    @RequestMapping(value = {"/join/waysOriginByPas"})
    @ResponseBody
    @ApiOperation(value = "获取已开通城市及线路数据接口（针对乘客）—— 已生效", response = SysPointSiteDto.class,
            notes = "DATA：线路起点包含的区域&固定点列表"
                    + "<br>matchCurPoint-是否默认（即是否与当前定位匹配：0否 1是）"
                    + "<br>uuid-起点UUID"
                    + "<br>type-起点类型（1区域 2固定点）"
                    + "<br>includeAreas-类型为区域时未包含区域 类型为固定点时为所属区县")
    public ResponseData<List<SysPointSiteDto>> waysOriginByPas(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "pasLng", value = "乘客经度") @RequestParam(required = false) Double pasLng,
            @ApiParam(name = "pasLat", value = "乘客纬度") @RequestParam(required = false) Double pasLat,
            @ApiParam(name = "onlyMatch", value = "是否仅返回最近定位出发点（0否 1是）") @RequestParam(required = false) Integer onlyMatch,
            @ApiParam(name = "businessType", value = "业务类型 3跨城拼车 5跨城小件") @RequestParam(required = false) Integer businessType,
            @ApiParam(name = "orderDemand", value = "订单需求 1普通拼车 2 机场专线") @RequestParam(required = false) Integer orderDemand,
            @ApiParam(name = "transferType", value = "接送机类型 1接机 2送机") @RequestParam(required = false) Integer transferType) {
        return sysWayService.waysOriginByPoint(appid, pasLng, pasLat, onlyMatch, businessType, orderDemand, transferType);
    }

    @RequestMapping(value = {"/join/waysDestByPas"})
    @ResponseBody
    @ApiOperation(value = "根据起点获取匹配线路终点接口—— 已生效", response = SysPointSiteDto.class,
            notes = "DATA：与起点匹配的的终点所包含的区域&固定点列表"
                    + "<br>matchCurPoint-是否默认（即是否与当前定位匹配：0否 1是）"
                    + "<br>uuid-终点UUID"
                    + "<br>type-终点类型（1区域 2固定点）"
                    + "<br>includeAreas-类型为区域时未包含区域 类型为固定点时为所属区县")
    public ResponseData<List<SysPointSiteDto>> waysDestByPas(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "originUuid", value = "线路起点ID", required = true) @RequestParam String originUuid,
            @ApiParam(name = "businessType", value = "业务类型 3跨城拼车 5跨城小件") @RequestParam(required = false) Integer businessType,
            @ApiParam(name = "orderDemand", value = "订单需求 1普通拼车 2 机场专线") @RequestParam(required = false) Integer orderDemand) {
        return sysWayService.waysDestByOrigin(appid, originUuid, orderDemand);
    }


    @RequestMapping(value = {"/join/listCarLevel"})
    @ResponseBody
    @ApiOperation(value = "获取车型列表接口 —— 已生效", response = CarModelDto.class)
    public ResponseData<Map<String, Object>> listCarLevel(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "originUuid", value = "起点UUID", required = true) @RequestParam String originUuid,
            @ApiParam(name = "destUuid", value = "终点UUID", required = true) @RequestParam String destUuid) {
        CarModelSiteParam carModelSiteParam = new CarModelSiteParam();
        carModelSiteParam.setBusinessType(CommonConstant.BUSINESS_TYPE_POOL);
        carModelSiteParam.setOriginUuid(originUuid);
        carModelSiteParam.setDestUuid(destUuid);
        carModelSiteParam.setAppid(appid);
        ResponseData<List<CarModelDto>> listRsd = carModelService.listCarModelByPointSite(carModelSiteParam);
        if (listRsd.isSuccess() && CollectionUtils.isNotEmpty(listRsd.getData())) {
            //最大座位数
            Integer maxPassengerSeats = 0;
            for (CarModelDto carLevelDto : listRsd.getData()) {
                maxPassengerSeats = maxPassengerSeats > carLevelDto.getMaxPassengerSeats() ? maxPassengerSeats : carLevelDto.getMaxPassengerSeats();
            }
            Map<String, Object> resultMap = new HashMap<>(4);
            resultMap.put("maxPassengerSeats", maxPassengerSeats);
            resultMap.put("carLevelList", listRsd.getData());
            return ResponseData.buildSuccessResponse(resultMap);
        }
        return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "车型获取失败");
    }

    @RequestMapping(value = {"/join/order/compute"})
    @ResponseBody
    @ApiOperation(value = "估价接口 —— 已生效", response = Map.class, notes = "响应数据结构参照专/快车系列，以实际接口返回为准")
    public ResponseData<ApiJoinValuationVo> computeOrder(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "token", value = "token") @RequestParam(required = false) String token,
            @ApiParam(name = "originUuid", value = "起点UUID", required = true) @RequestParam String originUuid,
            @ApiParam(name = "destUuid", value = "终点UUID", required = true) @RequestParam String destUuid,
            @ApiParam(name = "typeJoin", value = "拼车类型（1拼车 2包车 3小件 4二人快车）", required = true) @RequestParam Integer typeJoin,
            @ApiParam(name = "carModelUuid", value = "车型UUID", required = true) @RequestParam String carModelUuid,
            @ApiParam(name = "adultNum", value = "乘客数量（成人）", required = true) @RequestParam Integer adultNum,
            @ApiParam(name = "deparTime", value = "出发时间", required = false) @RequestParam(required = false) Long deparTime,
            @ApiParam(name = "originLng", value = "起点经度", required = true) @RequestParam Double originLng,
            @ApiParam(name = "originLat", value = "起点纬度", required = true) @RequestParam Double originLat,
            @ApiParam(name = "destLng", value = "终点经度", required = true) @RequestParam Double destLng,
            @ApiParam(name = "destLat", value = "终点纬度", required = true) @RequestParam Double destLat,
            HttpServletRequest request) {
        OrderEvaluateParam orderEvaluateParam = new OrderEvaluateParam();
        orderEvaluateParam.setAdultNum(adultNum);
        orderEvaluateParam.setAppid(appid);
        orderEvaluateParam.setCarModelUuid(carModelUuid);
        orderEvaluateParam.setDestUuid(destUuid);
        orderEvaluateParam.setOriginUuid(originUuid);
        orderEvaluateParam.setTypeJoin(typeJoin);
        if (deparTime == null) {
            orderEvaluateParam.setDeparTime(new Date());
        } else {
            orderEvaluateParam.setDeparTime(new Date(deparTime));
        }
        orderEvaluateParam.setOriginLng(originLng);
        orderEvaluateParam.setOriginLat(originLat);
        orderEvaluateParam.setDestLng(destLng);
        orderEvaluateParam.setDestLat(destLat);

        return orderFareService.joinValuation(orderEvaluateParam);
    }


    @RequestMapping(value = {"/token/join/order/create"})
    @ResponseBody
    @ApiOperation(value = "创建订单接口 —— 已生效", response = JsonOrderDetailVo.class,
            notes = "DATA：订单详情（跨城拼车订单状态主要以joinStatus为准）"
                    + "<br>joinStatus：100提交（待支付）、200预约中（已支付）、300预约成功（待安排）、400已安排（待出发）、500行程开始、600行程结束（已完成）"
                    + "<br>typeJoin-拼车类型：1拼车 2包车"
                    + "<br>typeSelf-代叫类型：1本人 2代叫"
                    + "<br>wayUuid：线路UUID"
                    + "<br>payStatus-支付状态：0未支付 1已支付 2退款中 3已退款"
                    + "<br>closeStatus-关闭状态：0正常 1关闭"
                    + "<br>closeType-关闭类型：PAS_CANCEL乘客主动取消 DRI_CANCEL司机端取消【预留】 TIME_OUT超时系统自动取消 ADMIN_CLOSE后台关闭 默认：null"
                    + "<br>resNum-订单剩余人数，只有拼车主订单才会有数据"
    )
    public ResponseData<Map<String, Object>> createOrder(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "typeTime", value = "订单行程类型（1实时订单 2预约订单）", required = true) @RequestParam Integer typeTime,
            @ApiParam(name = "deparTime", value = "预约出发时间（实时单可传空）") @RequestParam(required = false) Long deparTime,
            @ApiParam(name = "originUuid", value = "起点UUID", required = true) @RequestParam String originUuid,
            @ApiParam(name = "destUuid", value = "终点UUID", required = true) @RequestParam String destUuid,
            @ApiParam(name = "carModelUuid", value = "车型UUID", required = true) @RequestParam String carModelUuid,
            @ApiParam(name = "typeJoin", value = "拼车类型（1拼车 2包车）", required = true) @RequestParam Integer typeJoin,
            @ApiParam(name = "adultNum", value = "乘客数量（成人）", required = true) @RequestParam Integer adultNum,
            @ApiParam(name = "originCity", value = "起点城市") @RequestParam(required = false) String originCity,
            @ApiParam(name = "originAddress", value = "上车点") @RequestParam(required = false) String originAddress,
            @ApiParam(name = "originDetailAddress", value = "上车点的详细地址") @RequestParam(required = false) String originDetailAddress,
            @ApiParam(name = "originLng", value = "上车点经度") @RequestParam(required = false) Double originLng,
            @ApiParam(name = "originLat", value = "上车点纬度") @RequestParam(required = false) Double originLat,
            @ApiParam(name = "destCity", value = "终点城市") @RequestParam(required = false) String destCity,
            @ApiParam(name = "destAddress", value = "下车点") @RequestParam(required = false) String destAddress,
            @ApiParam(name = "destDetailAddress", value = "下车点的详细地址") @RequestParam(required = false) String destDetailAddress,
            @ApiParam(name = "destLng", value = "下车点经度") @RequestParam(required = false) Double destLng,
            @ApiParam(name = "destLat", value = "下车点纬度") @RequestParam(required = false) Double destLat,
            @ApiParam(name = "actualName", value = "实际乘车人") @RequestParam(required = false) String actualName,
            @ApiParam(name = "actualMobile", value = "实际乘车人电话") @RequestParam(required = false) String actualMobile,
            @ApiParam(name = "originAreaCode", value = "发起地行政区划代码") @RequestParam(required = false) String originAreaCode,
            @ApiParam(name = "passengerLng", value = "乘客发单经度") @RequestParam(required = false) String passengerLng,
            @ApiParam(name = "passengerLat", value = "乘客发单纬度") @RequestParam(required = false) String passengerLat,
            @ApiParam(name = "remark", value = "订单备注") @RequestParam(required = false) String remark,
            @ApiParam(name = "orderSource", value = "订单来源：1 APP移动端；2 微信公众号；3 电话叫车；4 pc网站； 5 后台下单； 6 小程序下单 7扫码下单") @RequestParam(required = false) Integer orderSource,
            @ApiParam(name = "orderDemand", value = "订单需求：1经济拼车 2二人快车") @RequestParam(required = false) Integer orderDemand,
            @ApiParam(name = "sourceRemark", value = "订单来源备注") @RequestParam(required = false) String sourceRemark,
            @ApiParam(name = "driverUuid", value = "司机ID") @RequestParam(required = false) String driverUuid,
            HttpServletRequest request) {
        JoinOrderParam joinOrderParam = new JoinOrderParam();
        joinOrderParam.setAppid(appid);
        if(deparTime!=null){
            joinOrderParam.setDeparTime(new Date(deparTime));
        }
        joinOrderParam.setUserUuid(getUserUid(request));
        joinOrderParam.setTypeTime(typeTime);
        joinOrderParam.setOriginSiteUuid(originUuid);
        joinOrderParam.setDestSiteUuid(destUuid);
        joinOrderParam.setCarModelUuid(carModelUuid);
        joinOrderParam.setTypeJoin(typeJoin);
        joinOrderParam.setAdultNum(adultNum);
        joinOrderParam.setOriginCity(originCity);
        joinOrderParam.setOriginAddress(originAddress);
        joinOrderParam.setOriginDetailAddress(originDetailAddress);
        joinOrderParam.setOriginLng(originLng);
        joinOrderParam.setOriginLat(originLat);
        joinOrderParam.setDestCity(destCity);
        joinOrderParam.setDestAddress(destAddress);
        joinOrderParam.setDestDetailAddress(destDetailAddress);
        joinOrderParam.setDestLng(destLng);
        joinOrderParam.setDestLat(destLat);
        joinOrderParam.setActualMobile(actualMobile);
        joinOrderParam.setActualName(actualName);
        joinOrderParam.setOriginAreaCode(originAreaCode);
        joinOrderParam.setPassengerLng(passengerLng);
        joinOrderParam.setPassengerLat(passengerLat);
        joinOrderParam.setRemark(remark);
        joinOrderParam.setOrderSource(orderSource);
        joinOrderParam.setOrderDemand(orderDemand);
        joinOrderParam.setSourceRemark(sourceRemark);
        joinOrderParam.setTypeModule(CommonConstant.BUSINESS_TYPE_POOL);
        return passengerFacade.createJoinOrder(joinOrderParam);
    }

    @RequestMapping(value = {"/token/join/home/order"})
    @ResponseBody
    @ApiOperation(value = "首页拼车订单接口 —— 已生效", response = JsonOrderDetailVo.class,
            notes = "DATA：订单详情（跨城拼车订单状态主要以joinStatus为准）"
                    + "<br>joinStatus：100提交（待支付）、200预约中（已支付）、300预约成功（待安排）、400已安排（待出发）、500行程开始、600行程结束（已完成）"
                    + "<br>typeJoin-拼车类型：1拼车 2包车"
                    + "<br>typeSelf-代叫类型：1本人 2代叫"
                    + "<br>wayUuid：线路UUID"
                    + "<br>payStatus-支付状态：0未支付 1已支付 2退款中 3已退款"
                    + "<br>closeStatus-关闭状态：0正常 1关闭"
                    + "<br>closeType-关闭类型：PAS_CANCEL乘客主动取消 DRI_CANCEL司机端取消【预留】 TIME_OUT超时系统自动取消 ADMIN_CLOSE后台关闭 默认：null"
                    + "<br>resNum-订单剩余人数，只有拼车主订单才会有数据"
    )
    public ResponseData<PageList<JsonOrderDetailVo>> homeOrder(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "typeModule", value = "typeModule") @RequestParam(required = false) Integer typeModule,
            @ApiParam(name = "orderDemand", value = "orderDemand") @RequestParam(required = false) Integer orderDemand,
            HttpServletRequest request) {
        //进行中的订单列表
        ApiJoinListParam joinListParam = new ApiJoinListParam();
        joinListParam.setIndexShow(1);
        joinListParam.setTypeModule(Optional.ofNullable(typeModule).orElse(CommonConstant.BUSINESS_TYPE_POOL));
        joinListParam.setOrderDemand(Optional.ofNullable(orderDemand).orElse(CommonConstant.CROSSTOWN_ORDER_DEMADN_ORDINARY));
        joinListParam.setPasUuid(getUserUid(request));
        joinListParam.setJoinStatus(Arrays.asList(OrderConstant.ORDER_JOIN_STATUS_INIT,
                OrderConstant.ORDER_JOIN_STATUS_SUBING, OrderConstant.ORDER_JOIN_STATUS_SUB_OK,
                OrderConstant.ORDER_JOIN_STATUS_WAIT_START, OrderConstant.ORDER_JOIN_STATUS_DRIVER_DEPARTURE,
                OrderConstant.ORDER_JOIN_STATUS_ARRIVE_POINT, OrderConstant.ORDER_JOIN_STATUS_PASSENGER_ABOARD,
                OrderConstant.ORDER_JOIN_STATUS_STARTED, OrderConstant.ORDER_JOIN_STATUS_CONFIRM_FARE,
                OrderConstant.ORDER_JOIN_STATUS_DRIVER_PAY, OrderConstant.ORDER_JOIN_STATUS_PASSENGER_PAY));
        return orderJoinService.joinPageList(joinListParam);
    }

    //TODO:预留接口
    //TODO:查询主订单、同时返回子订单列表
    //TODO:查询子订单、同时返回其主订单与关联子订单列表
    @RequestMapping(value = {"/token/join/order/infoRelated"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "完整拼车订单详情接口（含关联订单）【预留、此接口暂未优化，尽量少用】—— 已生效", response = ResponseData.class,
            notes = "输入任意拼车订单UUID，返回其关联主&子订单")
    public ResponseData<Map<String, Object>> infoRelatedOrder(@ApiParam(name = "orderUuid", value = "订单id", required = true) @RequestParam String orderUuid) {
        if (StringUtils.isEmpty(orderUuid)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "参数错误");
        }
        return orderJoinService.getInfoRelatedOrder(orderUuid);
    }

    @RequestMapping(value = {"/token/join/order/info"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "订单详情接口（单独主订单【不含子订单】或 单个子订单）—— 已生效", response = JsonOrderDetailVo.class)
    public ResponseData<JsonOrderDetailVo> infoOrder(@ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
                                                     @ApiParam(name = "orderUuid", value = "订单id", required = true) @RequestParam String orderUuid) {
        log.info("获取订单详情：{}", orderUuid);
        if (StringUtils.isEmpty(orderUuid)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "参数错误");
        }
        return orderService.getOrderDetail(orderUuid, null);
    }

    @RequestMapping(value = {"/token/join/order/cancel"})
    @ResponseBody
    @ApiOperation(value = "取消订单 —— 已生效", response = ResponseData.class)
    public ResponseData<Boolean> cancelOrder(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "orderUuid", value = "订单号", required = true) @RequestParam String orderUuid,
            @ApiParam(name = "closeType", value = "关闭类型", required = false) @RequestParam(required = false) String closeType,
            @ApiParam(name = "reason", value = "取消原因", required = false) @RequestParam(required = false) String reason) {
        closeType = StringUtils.isNotBlank(closeType) ? closeType : "PAS_CANCEL";

        JoinOrderParam joinOrdeParam = new JoinOrderParam();
        joinOrdeParam.setOrderUuid(orderUuid);
        joinOrdeParam.setCloseType(closeType);
        joinOrdeParam.setCloseReason(reason);
        return orderJoinService.closeJoinOrder(joinOrdeParam);
    }

    @RequestMapping(value = {"/join/way/info"})
    @ResponseBody
    @ApiOperation(value = "路线信息 —— 已生效")
    public ResponseData<Map<String, Object>> wayInfo(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "wayUuid", value = "路线UUID", required = true) @RequestParam String wayUuid,
            @ApiParam(name = "typeModule", value = "订单业务类型") @RequestParam(required = false) Integer typeModule,
            @ApiParam(name = "joinStatus", value = "订单状态") @RequestParam(required = false) Integer joinStatus,
            @ApiParam(name = "actualFare", value = "实际支付费用") @RequestParam(required = false) Double actualFare) {
        Map<String, Object> resultMap = new HashMap<>();
        //跨城小件时  取消规则与拼车有差异 需要支付一定取消费 查询线路 并根据订单状态判断取消费
        if (typeModule != null && CommonConstant.BUSINESS_TYPE_PARCEL == typeModule) {
            actualFare = (actualFare == null ? 0 : actualFare);
            SysWayRelateParam systemWayRelateParam = new SysWayRelateParam();
            systemWayRelateParam.setSystemWayUuid(wayUuid);
            ResponseData<SysWayInfoVo> responseData = sysWayService.getParcelRule(wayUuid);
            if (responseData.isSuccess()) {
                SysWayInfoVo systemWayInfoVo = responseData.getData();
                //小件取消费 当前规则 已派司机的小件订单取消时需要支付取消费 已出发订单将全额扣款
                Double parcelCancelFee = systemWayInfoVo.getParcelCancelFee() == null ? 0 : systemWayInfoVo.getParcelCancelFee();
                resultMap.put("cancelRule", systemWayInfoVo.getParcelCancelRule());
                if (joinStatus != null && OrderConstant.ORDER_JOIN_STATUS_WAIT_START == joinStatus) {
                    resultMap.put("cancelFee", parcelCancelFee > actualFare ? actualFare : parcelCancelFee);
                } else if (joinStatus != null && OrderConstant.ORDER_JOIN_STATUS_STARTED == joinStatus) {
                    resultMap.put("cancelFee", actualFare);
                }
            }
        } else {
            ResponseData<List<SysWayDto>> responseData = sysWayService.findWithOriginDest(MapUtils.build("wayUuid", wayUuid));
            if (responseData.isSuccess() && CollectionUtils.isNotEmpty(responseData.getData())) {
                resultMap.put("cancelRule", responseData.getData().get(0).getCancelRule());
            }
        }
        if (resultMap.size() > 0) {
            return ResponseData.buildSuccessResponse("获取线路信息成功", resultMap);
        }
        return ResponseData.buildErrorResponse(0, "获取线路信息成功");
    }

    @RequestMapping(value = {"/join/way/infoBySite"})
    @ResponseBody
    @ApiOperation(value = "通过起终点UUID获取路线信息 —— 已生效", response = SysWayDto.class)
    public ResponseData<SysWayDto> wayInfoBySite(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "originUuid", value = "路线起点UUID", required = true) @RequestParam String originUuid,
            @ApiParam(name = "destUuid", value = "路线终点UUID", required = true) @RequestParam String destUuid,
            HttpServletRequest request) {
        Map<String, Object> build = MapUtils.build(4);
        build.put("originSiteUuid", originUuid);
        build.put("destSiteUuid", destUuid);
        ResponseData<List<SysWayDto>> responseData = sysWayService.findWithOriginDest(build);
        if (responseData.isSuccess() && CollectionUtils.isNotEmpty(responseData.getData())) {
            return ResponseData.buildSuccessResponse(responseData.getData().get(0));
        }
        return ResponseData.buildErrorResponse(responseData.getErrCode(), responseData.getMsg());
    }

    @RequestMapping(value = {"/join/way/pageCancelRule"})
    @ApiOperation(value = "路线取消订单规则H5 —— （页面待补充）", response = HttpServletResponse.class, notes = "")
    public String wayCancelRule(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "wayUuid", value = "路线UUID", required = true) @RequestParam String wayUuid,
            HttpServletRequest request, Model model) {
        ResponseData<List<SysWayDto>> responseData = sysWayService.findWithOriginDest(MapUtils.build("wayUuid", wayUuid));
        if (responseData.isSuccess() && CollectionUtils.isNotEmpty(responseData.getData())) {
            model.addAttribute("way", responseData.getData().get(0));
        }
        return "way/cancel-rule";
    }

    @ResponseBody
    @RequestMapping(value = {"/token/join/order/parcel/uploadPhoto"})
    @ApiOperation(value = "货件图片上传接口", response = ResponseData.class)
    public ResponseData<Map<String, Object>> uploadPhoto(
            @ApiParam(name = "appid", value = "APP标识", required = false) @RequestPart String appid,
            @ApiParam(name = "parcelPhoto", value = "货件照片", required = true) @RequestPart MultipartFile parcelPhoto,
            @ApiParam(name = "passengerMobile", value = "用户手机号码", required = true) @RequestPart String passengerMobile) {
        String fileName = parcelPhoto.getOriginalFilename();
        String lastName = StringUtils.substringAfterLast(fileName, ".");
        if (!lastName.equals(MagicConstant.PICTURE_SUFFIX_JPG) && !lastName.equals(MagicConstant.PICTURE_SUFFIX_PNG)
                && !lastName.equals(MagicConstant.PICTURE_SUFFIX_JPEG) && !lastName.equals(MagicConstant.PICTURE_SUFFIX_BMP)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "图片格式不正确，请重新选择！");
        }
        //上传货件图片
        ResponseData<String> responseData = FileUploadUtil.uploadImage(parcelPhoto, appid, passengerMobile, "parcelphoto");
        if (!responseData.isSuccess() || StringUtils.isEmpty(responseData.getData())) {
            return ResponseData.buildErrorResponse(responseData.getErrCode(), responseData.getMsg());
        }
        return ResponseData.buildSuccessResponse("上传成功", MapUtils.build("photoPath", responseData.getData()));
    }

}
